<?php
require_once("userView.php");
require_once(CORE_DIR.'userModel.php');
require_once(CORE_DIR.'groupModel.php');

class addAction extends authAction{

	function __construct(){
		$this->view = new userView();
	}

	public function run($get, $post, $viewtype) {
		parent::run($get,$post,$viewtype);
		
		$uModel = new userModel();
		$gModel = new groupModel();		
		
		if (isset($get["nick"])){
			$userNick = $get["nick"];	
			$userFName = $get["fname"];
			$userLName = $get["lname"];
			$userRole = $get["role"];
			$taskType = $get["tasktype"];
			$userEmail = $get["email"];
			$userPass = $get["pass"];
			$fbUid = $get["fbuid"];
			$groupIds = $get["group"];
			
			$lastInsertId = $uModel->addUser($userNick, $userFName, $userLName, $userRole, $userEmail, $userPass, $taskType, $fbUid);
			$gModel->addUserToGroup($groupIds, $lastInsertId);	
			$status = 0;
			$id = 0;
			if ($lastInsertId > 0){
				$status = 1;
				$id = $lastInsertId;
			}
			$this->view->setProperty("status", $status);
			$this->view->setProperty("id", $id);
			$this->view->showAddUser();
		}
		else{
			$this->view->showBadCmd();
		}	
			
	}
}
?>